package ToYesterday.Day02.linklist;

public class Linklist {
    public static class Node<T>{
        T data;
        Node next;
        Node(){
            data=null;
            next=null;
        }
        Node(T mdata,Node mnext){
            data=mdata;
            next=mnext;
        }
        Node(T mdata){
            data=mdata;
            next=null;
        }
    }

     static Node head;
     static int size;
    Linklist(){
        head = new Node();
        size=0;
    }
    

    int getSize() {
        System.out.println(size);
        return size;
    }
    void initList(){
    }

    static void insertHeadList(Linklist linklist,Node p){
        p.next = linklist.head;
        linklist.head = p;
    }

    static void insertListRear(Linklist linklist,Node p){
        Node q = linklist.head;
        if (linklist.head.data==null){
            linklist.head=p;
        }else {
            while (q.next!=null){
                q=q.next;
            }
            q.next = p;
        }
    }

    static void getNode(Linklist linklist, int i,Node q){
        int j=1;
        Node p = linklist.head;
        while (j<i){
            p=p.next;
            j++;
        }
        q.next=p.next;
        q.data=p.data;
    }


    static void getList(Linklist linklist){
        int i =0;
        while(linklist.head!=null){
            i++;
            System.out.println(linklist.head.data+"   "+i);
            linklist.head=linklist.head.next;
        }
    }

}
